﻿using System.Collections.Generic;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using RMH.Entities;
using RMH.Services;
using RMH.Web.Controllers;

namespace RMH.UnitTests.Web.Controllers.StayControllerSpecs
{
    [TestFixture]
    public class StayController_when_creating_a_stay_for_patient_with_paayment_info_and_missing_payment_mehod : base_automock_test
    {
        private ViewResult result;
        private Stay stay = new Stay() { Payment = new Payment() { Amount = 10 } };
        private int patientId = 1;
        private StayController stayController;
        string expectedErrorMessage = "Payment Method is required.";
        private int expectedNumErrors = 1;
        private string propName = "Payment.Method";

        public override void establish_context()
        {
            Mock<IStayService>()
                .Setup(s => s.GetNewStayForPatient(patientId))
                .Returns(stay);
        }

        public override void because()
        {
            stayController = Create<StayController>();
            result = stayController.Edit(stay);
        }

        [Test]
        public void should_cause_model_state_to_be_invalid()
        {
            stayController.ModelState.IsValid.ShouldEqual(false);
        }

        [Test]
        public void returns_a_single_validation_error_message_for_missing_payment_method()
        {
            stayController.ModelState[propName].Errors.Count.ShouldEqual(expectedNumErrors);
            stayController.ModelState[propName].Errors[0].ErrorMessage.ShouldEqual(expectedErrorMessage);
        }
    }
}
